<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
	<head>
		<meta charset="utf-8">
		<title>学生端登录/注册</title>
		<script src="../static/js/jquery-3.3.1.min.js"></script>
		<script src="../static/js/bootstrap.min.js"></script>
		<link href="../static/css/bootstrap.min.css" type="text/css" rel="stylesheet" />

		<script type="text/javascript" src="../static/js/wow.min.js"></script>
		<link href="../static/css/animate.css" type="text/css" rel="stylesheet"/>


		<style>
			.page-header h3{
				font-weight: 800;
			}
		</style>

		<script>
			$(document).ready(function(){


				// 登录
				$('.loginBtn').click(function () {


					if ($('#loginId').val().length==0){
						alert("账号不能为空")
						return false;
					}
					if ($('#loginPassword').val().length==0){
						alert("密码不能为空")
						return false;
					}

					$.post(
							"${pageContext.request.contextPath}/studentLogin",
							$('#loginForm').serialize(),
							function (data) {
								if (data == 0) {
									alert("登录失败");
								}else if(data==1){
									var $url = "${pageContext.request.contextPath}" +'/jsp/admin/student/admin.jsp';
									$(window).attr('location',$url);

								}
							}
					)
				});

				//展示注册页
				$('.registerNewBtn').click(function(){		
					
					$('.register').show();
					$('.login').hide();
					return false;
				});

				//展示登录页面
				$('.loginNewBtn').click(function(){		
					
					$('.register').hide();
					$('.login').show();
					return false;
				});

				// 注册
				$('.registerBtn').click(function () {


					if ($('#studentId').val().length==0){
						alert("账号不能为空")
						return false;
					}
					if ($('#studentPassword').val().length==0){
						alert("密码不能为空")
						return false;
					}

					if ($('#confirmPassword').val()!=$('#studentPassword').val()){
						alert("两次密码不相同")
						return false;
					}
					if ($('#studentName').val().length==0){
						alert("姓名不能为空")
						return false;
					}
					if ($('#studentMajor').val().length==0){
						alert("姓名不能为空")
						return false;
					}

					$.post(
							"${pageContext.request.contextPath}/studentRegister",
							$('#registerForm').serialize(),
							function (data) {
								console.log(data);
								if(data>0){
									alert("注册成功！");
								}else{
									alert("注册失败！")
								}
							}
					)
				});



				//检查账号是否被占用
				$('#studentId').blur(function () {
					$.get(
							"${pageContext.request.contextPath}/queryStudentIdIsExist",
							{studentId:$('#studentId').val()},
							function (data) {
								if(data>0){
									$('.studentIdTip').text("该账号已被注册！");
								}else{
									$('.studentIdTip').text("");
								}
							}
					);
				});

				$('.index').click(function () {
					var $url = "${pageContext.request.contextPath}" +'/index.jsp';
					$(window).attr('location',$url);
				});

				//wow 动画
				var wow = new WOW({
					boxClass: 'wow',
					animateClass: 'animated',
					offset: 0,
					mobile: true,
					live: true
				});
				wow.init();

			});
		</script>

	</head>


	<body background="../static/img/bg.png">


		<div class="contains" style="width: 50%;  margin: 200px auto;">
			<div class="logo text-center"><img src="../static/img/logo.png" width="200px" /></div>



			<div class="login">
				<script>
					$('.login').show();
				</script>
				<div class="panel panel-collapse panel-primary text-center">
					<div class="page-header panel-danger">
						<h3 class="text-info wow bounceInDown"  data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
							data-wow-iteration="1">欢迎使用网络在线选课系统-学生登录</h3>
					</div>
					<div class="panel-body text-center">
						<form class="form form-horizontal" id="loginForm" method="post" >
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生账号：<input type="text" class="form-control" name="studentId" id="loginId"  placeholder="请输入账号" /></label>
								<label class="tip studentIdTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生密码：<input type="password" class="form-control" name="studentPassword" id="loginPassword"  placeholder="请输入密码" /></label>
								<label class="tip studentPasswordTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<button class="btn btn-sm btn-link modifyBtn"><a href="checkUser.jsp">忘记密码?</a></button>
								|
								<button class="btn btn-sm btn-link registerNewBtn">注册一个新账号?</button>
							</div>
							<div class="form-group form-inline">
								<button class="btn btn-info  loginBtn wow bounceInRight" data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
										data-wow-iteration="1">登录</button>
								<button type="button" class="btn btn-danger index wow bounceInLeft"   data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
										data-wow-iteration="1">主页</button>
								<label class="tip statusTip text-danger"></label>
							</div>
						</form>
					</div>
					<div class="panel-footer ">
						<h5>@2019-2019 JSP期末项目</h5>
					</div>

				</div>
			</div>


			<div class="register">
				<script>
					$('.register').hide();
				</script>
				<div class="panel panel-collapse panel-primary text-center">
					<div class="page-header panel-danger">
						<h3 class="text-info wow bounceInDown"  data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
							data-wow-iteration="1">欢迎使用网络在线选课系统-学生注册</h3>
					</div>
					<div class="panel-body text-center">
						<form class="form form-horizontal" id="registerForm" method="post">
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生账号：<input type="text" class="form-control" name="studentId" id="studentId" placeholder="请输入账号" /></label>
								<label class="tip studentIdTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生密码：<input type="password" class="form-control" name="studentPassword" id="studentPassword" placeholder="请输入密码" /></label>
								<label class="tip studentPasswordTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">确认密码：<input type="password" class="form-control" id="confirmPassword" placeholder="请再输入密码" /></label>
								<label class="tip confirmTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生姓名：<input type="text" class="form-control" name="studentName" id="studentName" placeholder="请输入姓名" /></label>
								<label class="tip studentNameTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<label class="wow fadeInDown" data-wow-duration="1s" data-wow-delay="0.2s" data-wow-offset="10"
									   data-wow-iteration="1">学生专业：<input type="text" class="form-control" name="studentMajor" id="studentMajor" placeholder="请输入专业" /></label>
								<label class="tip studentMajorTip text-danger"></label>
							</div>
							<div class="form-group form-inline">
								<button class="btn btn-danger  registerBtn wow bounceInRight" data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
										data-wow-iteration="1">注册</button>
								<button type="button" class="btn btn-danger index wow bounceInLeft"   data-wow-duration="1s" data-wow-delay="0.5s" data-wow-offset="10"
										data-wow-iteration="1">主页</button>
								<label class="tip statusTip text-danger"></label>
							</div>
							<div class="form-group form-inline">

								已经有账户了?
								<button class="btn  btn-link loginNewBtn">点击登录</button>
							</div>
						</form>
					</div>

					<div class="panel-footer ">
						<h5>@2019-2020 JSP期末项目</h5>
					</div>
				</div>
			</div>
		</div>

	</body>
</html>
